<!DOCTYPE html>
<html lang="zh-cn">
<head>
<#include "/common/freemarker/include_css.ftl">
<title>父菜单选择</title>
</head>
<body>
 

 
<link rel="stylesheet" type="text/css" href="<@context/>common/zTree_v3/css/zTreeStyle/zTreeStyle.css" />
  


<div class="row ">		 
	
    <div class="col-md-2" style="min-width: 400px;">
		<div class="panel panel-default">
		    <div class="panel-heading">
		                  菜单树
		    </div>
		    <div class="panel-body"  >
		        
				<ul id="org-tree" class="ztree" style="width:260px; overflow:auto;"></ul>
		    </div>
		    <div class="panel-footer">
		         <div class="form-group">
		         	<div class="col-md-2">
		         		<button id="btnCancel" class="btn btn-primary" onclick="doConfirm();" type="button">确   定</button>
		         		<button id="btnCancel" class="btn btn-default" onclick="art.dialog.close();" type="button">取   消</button>
		         		<button id="btnCancel" class="btn btn-default" onclick="doEmpty();" type="button">空数据</button> 
		         	</div>
		         </div>
		    </div>
		 </div>
	</div>	 
</div>

<#include "/common/freemarker/include_js.ftl">
<script type="text/javascript" src="<@context/>common/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<@context/>common/zTree_v3/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="<@context/>js/mindao/mindao.tree.js"></script>

 <SCRIPT type="text/javascript" >
	var zTree;
	var isMultiplePara=art.dialog.data("isMultiple");
	var isMultiple=(isMultiplePara=='true')?true:false;
	var setting = {
		check: {
			enable: isMultiple,
			chkboxType:{ "Y" : "", "N" : "" }
		},	
		view: {
			dblClickExpand: false,
			showLine: true,
			selectedMulti: true
		},
		data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: ""
			}
		}
	};
	<#if treeNodes?exists> 
		var zNodes =  JSON.parse('${treeNodes}');
	<#else>
		var zNodes =  [];
	</#if>
	
	$(document).ready(function(){
		var t = $("#org-tree");
		t = $.fn.zTree.init(t, setting, zNodes);
		var zTree = $.fn.zTree.getZTreeObj("org-tree");
		<#if selectNodeId?exists>
			if (isMultiple==false){
				zTree.selectNode(zTree.getNodeByParam("id", ${selectNodeId}));
			}else{
				<#if selectNodeId!="">
				    <#list selectNodeId?split(",") as tId>
						zTree.checkNode(zTree.getNodeByParam("id", ${tId}), true, true);
					</#list>
				</#if>
			}
		</#if>
	});	
	
	
	var parentWindow = art.dialog.data("parentWindow");
	var idName = art.dialog.data("idName");
	var txtName = art.dialog.data("txtName");
	var openerDoc=parentWindow.document;
	 
	function doConfirm(){
		var treeObj = $.fn.zTree.getZTreeObj("org-tree");
		if (isMultiple==false){
			var nodes = treeObj.getSelectedNodes();
		}else{
			var nodes=treeObj.getCheckedNodes(true);
		}
		
		if (nodes == null || nodes == "") {
			showPopBox(2, "请选择一个节点！");
			return false;
		}
		
		var retarr = new Array(2);
		retarr[0] = "";
		retarr[1] = "";
 		for (var oindex = 0; oindex < nodes.length; oindex++) {
			    if (oindex == 0) {
			        retarr[0] = nodes[oindex].id;
			        retarr[1] = nodes[oindex].name;
			    } else {
			        retarr[0] = retarr[0] + "," + nodes[oindex].id;
			        retarr[1] = retarr[1] + "," + nodes[oindex].name;
			    }
			}
		
		if (openerDoc.all(idName)!=null){
			openerDoc.all( idName ).value = retarr[0];
		}
		if (openerDoc.all(txtName)!=null){
			openerDoc.all( txtName ).value = retarr[1];
		}	
		
		art.dialog.close();
	}
	function doEmpty(){
		if (openerDoc.all(idName)!=null){
			openerDoc.all( idName ).value = "";
		}
		if (openerDoc.all(txtName)!=null){
			openerDoc.all( txtName ).value = "";
		}		
		art.dialog.close();
	}
	
</SCRIPT>		

</body>
</html>    